﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ECommerce.Library;
using ECommerce.Library.Web;
using eShop.Business;
using eShop.DataAccess;
using eShop.Model;

public partial class admin_newsletter_template_details : SiteAdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //SessionManager.CurrentAdminPage = AdminPageName.NewsletterTemplateDetails;
        if (!IsPostBack)
        {
            BindInfo();
        }

    }

    private void BindInfo()
    {
        EmailTemplate newsletterTemplate = EmailTemplateDAO.GetTblEmailTemplateByEmailTemplateId(NewsletterTemplateId);
        txtTemplateId.Text = newsletterTemplate.EmailTemplateId.ToString();
        txtTemplateName.Text = newsletterTemplate.EmailSubject;
        tbTemplateDesign.Text = newsletterTemplate.EmailBody;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        EmailTemplate iNewsletterTemplate = EmailTemplateDAO.GetTblEmailTemplateByEmailTemplateId(Convert.ToInt32(txtTemplateId.Text));
        iNewsletterTemplate.EmailSubject = txtTemplateName.Text;
        iNewsletterTemplate.EmailBody = tbTemplateDesign.Text;

        if (EmailTemplateDAO.Save(iNewsletterTemplate))
        {
                lblCRUDMessege.Text = "Operation Successful.";
                lblCRUDMessege.CssClass = "message";
        }
        else
        {
            lblCRUDMessege.Text = "Operation Not Successful.";
            lblCRUDMessege.CssClass = "errorMessage";
        }
        BindInfo();
    }

    private int NewsletterTemplateId
    {
        get
        {
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
                return 0;
            return Convert.ToInt32(Request.QueryString["id"]);
        }
    }
}
